package Offer016;

import java.util.HashMap;
import java.util.Map;

/**
 * . 不含重复字符的最长子字符串
 * @author 23737
 * @time 2021.12.11
 */
public class Test {
    public static void main(String[] args) {

    }
}

/**
 * map存储
 */
class Solution {
    public int lengthOfLongestSubstring(String s) {
        int len = s.length();
        if(len == 0){
            return  0;
        }
        Map<Character,Integer> map = new HashMap<>();
        int res = 1;
        int start = -1;
        for(int i=0; i<len; i++){
            char c = s.charAt(i);
            if(map.containsKey(c)){
                start = Math.max(start,map.get(c));
            }
            map.put(c,i);
            res = Math.max(res,i - start);
        }
        return res;
    }
}
